import java.sql.*;

public class MysqlConnect{
  public static void main(String[] args) {
  System.out.println("MySQL Connect Example.");
  Connection conn = null;
  Statement stmt = null;
  ResultSet rst=null;
  String url = "jdbc:mysql://localhost:3306/";
  String dbName = "unilearn";
  String driver = "com.mysql.jdbc.Driver";
  String userName = "root"; 
  String password = "";
  try {
  Class.forName(driver).newInstance();
  conn = DriverManager.getConnection(url+dbName,userName,password);
  System.out.println("Connected to the database");
  if(!conn.isClosed())
  {
	stmt = conn.createStatement();
	rst=stmt.executeQuery("select * from user");
	while(rst.next())
	{
		System.out.println(""+ rst.getString("login_id"));
	}
  }
  conn.close();
  System.out.println("Disconnected from database");
  } catch (Exception e) {
  e.printStackTrace();
  }
  }
}
